package com.neutech.pha.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.neutech.pha.mapper.PhaMapper;
import com.neutech.pha.service.PhaService;

import com.neutech.po.Pha;
import com.neutech.vo.ToPhaVo;


@RestController
@RequestMapping("/neupha")
public class PhaController {
	@Autowired
	private PhaMapper phaMapper;
	@Autowired
	private PhaService phaService;
	
	@RequestMapping(value="addNewPha",method=RequestMethod.POST)
	public String addNewPha(@RequestBody Map<String, Object> drugs){
		System.out.println(drugs.get("drugsName"));
		phaService.addNewPha(drugs);
		return "success";
	}
	
	/**
	 * 增加药品
	 * @param neuPha
	 * @return 成功"success" 失败"error"
	 */
	@RequestMapping(value="/addPha",method=RequestMethod.POST)
	public String addPha(Pha neuPha){
		int phaNum = phaMapper.addPha(neuPha);
		if(phaNum == 1){
			return "success";
		}else{
			return "error";
		}
	}
	@RequestMapping(value="/queryPha",method=RequestMethod.GET)
	public List<Pha> queryPha(){
		return phaService.queryPha();
	}
	
	@RequestMapping(value="/Pha",method=RequestMethod.GET)
	public String pha(Pha pha){
		System.out.println(pha.getId()+","+pha.getDrugsName());
		return "success";
	}
	@RequestMapping(value="/deletePha")
	public String deletePha(Pha neuPha){
		int phaNum = phaMapper.deletePha(neuPha);
		if(phaNum == 1){
			return "delete success";
		}else{
			return "error";
		}
	}
	
	@RequestMapping(value="/updatePha",method=RequestMethod.POST)
	public void updatePha(Pha neuPha){
		phaMapper.updatePha(neuPha);
	}
	
	@RequestMapping("/phaList")
	public ToPhaVo tpPha(){
		return phaService.toPhaVo();
	}

}
